//
//  BLTableControl.m
//  blanket
//
//  Created by Mac on 2017/12/5.
//  Copyright © 2017年 stoneobs@icloud.com. All rights reserved.
//

#import "BLTableControl.h"

@implementation BLTableControl

- (instancetype)initWithFrame:(CGRect)frame leftTitle:(NSString *)leftTitle placeHolder:(NSString *)placeHolder{
    if (self == [super initWithFrame:frame]) {
        self.leftLable = [[STLabel alloc] initWithFrame:CGRectMake(0, 0, 80, self.height)
                                                         text:leftTitle
                                                    textColor:FirstTextColor
                                                         font:14
                                                  isSizetoFit:NO
                                                textAlignment:NSTextAlignmentCenter];
        [self.leftLable st_showRightLine:20];
        [self addSubview:self.leftLable];
        
        self.textFiled = [[UITextField alloc] initWithFrame:CGRectMake(self.leftLable.right + 10, 0, self.width - self.leftLable.right - 20, 30)];
        self.textFiled.centerY = self.height / 2;
        self.textFiled.placeholder = placeHolder;
        [self addSubview:self.textFiled];
        [self st_setBorderWith:0.5 borderColor:KL_secendTextColor cornerRadius:5];
        [self addNotifacations];
    }
    return self;
}
- (void)setSelected:(BOOL)selected{
    [super setSelected:selected];
    if (selected) {
        [self st_setBorderWith:0.5 borderColor:BL_BlueBackGroundColor cornerRadius:5];
    }else{
        [self st_setBorderWith:0.5 borderColor:KL_secendTextColor cornerRadius:5];
    }
}
#pragma mark --Notifacation
- (void)addNotifacations{
    
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(textFieldTextDidBeginEditingNotification:)
                                                 name:UITextFieldTextDidBeginEditingNotification
                                               object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(textFieldTextDidEndEditingNotification:)
                                                 name:UITextFieldTextDidEndEditingNotification
                                               object:nil];
    
}
- (void)textFieldTextDidBeginEditingNotification:(NSNotification*)notif{
    if (notif.object == self.textFiled) {
        self.selected = YES;
    }
}
- (void)textFieldTextDidEndEditingNotification:(NSNotification*)notif{
    if (notif.object == self.textFiled) {
        self.selected = NO;
    }
}
- (void)dealloc{
    
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end
